package Classes.GameUtils
{
	import Classes.GameViews.ViewIcons.ViewIcon;
	import Classes.GameViews.ViewPanels.VP_RewardItemWindon;
	import Classes.Managers.M_ConfigData;
	import Classes.Managers.M_Languages;
	import Classes.staticinfo.Language;
	
	import UIComponents.IUseItem;
	
	import flash.display.DisplayObject;
	import flash.events.Event;

	public class RewardWindons_deal
	{
		private static var _instance:RewardWindons_deal;
		
		public function RewardWindons_deal()
		{
		}
		
		public static function get instance():RewardWindons_deal
		{
			if(!_instance)_instance=new RewardWindons_deal();
			return _instance;
		}
		
		public function hanldWinFun(vpWin:VP_RewardItemWindon,str:String):void
		{
			VP_RewardItemWindon.instance.openRewardItemWindon(spiltData(str));
			VP_RewardItemWindon.instance.interfaceUI.addEventListener("shareSomething",shareFun);
		}
		
		private function shareFun(e:Event):void
		{
//			GU_dealSharePreWin.instance.haldSharePreFun();	
			if(M_ConfigData.instance.isOpenNewThing)
			{
				new GU_NewThingsControler(GU_NewThingsInfo.instance.getNewThingsByType(10));
				//				M_Communication.instance.send(125000);
			}
			VP_RewardItemWindon.instance.closeWin();
		}
		
		public function spiltData(str:String):Array
		{
			var relustArr:Array=new Array();
			var comm:String=str.split("|")[0];
			var itemStr:String=str.split("|")[1];
			var pointArr:Array=itemStr.split(",");
			for(var i:int=0;i<pointArr.length;i++)
			{
				var o:Object=new Object();
				var tmp:Array=pointArr[i].split("-");
				o.itemNum=tmp[1];
				var vi:DisplayObject;
				var iUseItem:IUseItem=null;
				switch(Number(tmp[0]))
				{
					case 1://行动力
						vi=ViewIcon.creat({sourceName:"icon0.swf",picName:"Icon_Act"});
						o.itemName=Language.act;
						break;
					case 2://金币
						vi=ViewIcon.creat({sourceName:"icon0.swf",picName:"Icon_JB"});
						o.itemName=Language.jb;
						break;
					case 3://O币
						vi=ViewIcon.creat({sourceName:"icon0.swf",picName:"Icon_OB"});
						o.itemName=Language.ob;
						break;
					case 4://经验
						vi=ViewIcon.creat({sourceName:"icon0.swf",picName:"Icon_Exp"});
						o.itemName=Language.exp;
						break;
					default:
						if(null!=tmp[0] && ""!=tmp[0])
						{
							iUseItem=GD_deal.instance.getDataById(tmp[0]);
							vi=iUseItem.itemPic;
							vi["setNumSpVisiable"](false);
						}
				}
				if(vi)
				{
					vi.scaleX=0.5;
					vi.scaleY=0.5;
					o.itemIcon=vi;
					if(null!=iUseItem)
					{
						o.itemName=iUseItem.itemName;
						o.des=iUseItem.description;
					}
					relustArr.push(o);
				}
			}
			return relustArr;
		}
	}
}